/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Text, useTheme,} from "customize-easy-ui-component";
import { ReportViewProps, } from "../../common/base";
import {
    末尾链接, 落款单位地址,
} from "../../common/rarelyVary";
import {检验结论报告,} from "./repView";
import {useSubRepMain} from "../../hook/useSubRepMain";
import {useRepMenuDirItems} from "../../hook/useMainRepUrlOr";
import {全面检验报告附页} from "./viewMacr";
import {ReportFirstPageHeadnMbbm, 注意事项MVS, 目录页VS, 首页设备概况MVS} from "../rarelyVary";
import {VsProjects默认} from "../editorDJ";
import {useItemsMapPressure} from "../../common/pressure";
import {资料审查报告} from "./viewReview";
import {安全附件检验} from "./viewSAcces";
import {附加检验报告} from "./viewAddon";


export const ReportView: React.FunctionComponent<ReportViewProps> = ({
    repId,   source: orc,  verId,rep,
}) => {
  const theme= useTheme();
    const [mapFxian]=useItemsMapPressure({ projects:orc.Projects });
  // const [[redundance,bindRedund] ] =useAreaFoldable(false,[undefined ]);
  // const THICKM_VS_Cmp= 测厚报告模板[`${THICKM_VS_Ver}` as keyof typeof 测厚报告模板]; 【定规则】一般报告必须中间必有-符号，可做嵌入式的分项报告模板号码中间必须_符号。
   //内嵌模式的:在模板里面就已经敲定了版本号,分项模板编代码,不用让后端去建立Report对象; THICK_MS 独立目录的，既可以独立流转，也能直接内嵌式的。可是：单线图和特性表这样的分项是只能内置的分项形态做的复用引入组件。
  //而公共模板的分项，都有独立的模板编码的，缺点=编辑器和主报告是脱离即没有一块显示全部的原始记录的。   # 单线图和特性表还是采用复用内置模式非公共模板，不支持独立流转形态。
  const [renderThickm]= useSubRepMain("cm/thickm", {nestMd:'THICK_MS',orc, repId:repId!, rep, NestMbVer:1});
  const [renderSpectrVs]= useSubRepMain("cm/spectrVs", {nestMd:'SPECTR_VS', orc, repId:repId!, rep, NestMbVer:1});
    // const [renderTofd]= useSubRepMain("cm/tofd", {nestMd:'TOFD_TS', orc, repId:repId!, rep, NestMbVer:1});
    const [rootMenu]=useRepMenuDirItems(VsProjects默认, orc.Projects, `/reportView/${rep?.modeltype}/ver/${verId}/${repId}`);
    const [renderUtrSonic]= useSubRepMain("cm/sonic", {nestMd:'SONIC_TS',orc, repId:repId!, rep, NestMbVer:1});
    const [renderRadioTs ]= useSubRepMain("cm/radio", {nestMd:'RADIO_TS',orc, repId:repId!, rep, NestMbVer:1});
    const [permeation ]= useSubRepMain("cm/permeation", {nestMd:'PERME_TS',orc, repId:repId!, rep, NestMbVer:1});
    const [magnetic ]= useSubRepMain("cm/magnetic", {nestMd:'MAGNT_TS',orc, repId:repId!, rep, NestMbVer:1});
    // const [optical ]= useSubRepMain("cm/optical", {nestMd:'OPTIC_TS',orc, repId:repId!, rep, NestMbVer:1});
    const [hardness ]= useSubRepMain("cm/hardness", {nestMd:'HARD_TS',orc, repId:repId!, rep, NestMbVer:1});
    const [gasproof ]= useSubRepMain("cm/gasproof", {nestMd:'GASPR_TS',orc, repId:repId!, rep, NestMbVer:1});
    //手机菜单可安排的：一层7位置+二层9位置。报告最多安排16个菜单。 加了, {time: Date()});：URL强制刷新！才能真正跳转成功到位置
  return (
    <React.Fragment>
        {rootMenu}
        <div css={{
            "@media not print": {
                marginTop: '1rem',
                marginBottom: '1rem'
            }
        }}>
            <div css={{
                display: 'flex',
                flexDirection: 'column',
                justifyContent: 'space-between',
                "@media print": {
                    height: '100vh',       //一张纸的高度！同时配合 pageBreakAfter: 'always', 来约束特定纸张大小；
                    // overflowY: 'hidden',     //只想打印一页的情形！！ 纸张规格；假如实际的数据超出自然不打印的！ 不加上打印重叠的；
                    pageBreakInside: 'avoid',
                }
            }}>
                {ReportFirstPageHeadnMbbm({theme, rep, mbbm: 'FJB/TM-1007-1-0-2022'})}
                <div>
                    <Text variant="h3" css={{
                        textAlign: 'center',
                        "@media (min-width:690px),print and (min-width:538px)": {
                            fontSize: theme.fontSizes[6],
                        }
                    }}>
                        移动式压力容器全面检验报告
                    </Text>
                    <br css={{"@media not print": {display: 'none'}}}/>
                    <Text variant="h5" css={{
                        textAlign: 'center',
                    }}> （ FJB/RC 10371-2022 ）
                    </Text>
                </div>
                <div css={{
                    "@media print": {
                        // minHeight: '-webkit-fill-available',
                    }
                }}>
                    {首页设备概况MVS({theme, orc, rep})}
                </div>
                <div css={{
                    textAlign: 'center',
                    "@media print": {
                        // pageBreakAfter: 'always',
                        pageBreakInside: 'avoid'
                    }
                }}>
                    {落款单位地址}
                </div>
            </div>

            {注意事项MVS({
                rep,
                comply: '书为依据《移动式压力容器安全技术监察规程》（TSG R0005）及第1、2、3号修 改单、《压力容器定期检验规则》（TSG R7001）制定，适用于移动式压力容器全面检验报 告的结论报告，检验结论仅代表该设备在检验时的安全状况'
            })}

            {目录页VS({theme, orc, rep, suffix: true})}

            {检验结论报告({theme, orc, rep})}

            {资料审查报告({theme, orc, rep})}

            {/*若用简易函数 全面检验报告附页({theme, orc, rep}) 方式的里面用了useCallback 在无数据和有数据切换时刻旧导致Hook报错
                Warning: React has detected a change in the order of Hooks called by ReportView. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
                6. useContext                 useCallback
                而 最后那个“附加检验报告” 里面没有用hook 所以不会报错！
            */}
            {mapFxian.get('容器全面检验报告附页')?.do &&
                <全面检验报告附页 theme={theme} orc={orc} rep={rep}/>
            }

            {mapFxian.get('壁厚测定报告')?.do && <>
                {renderThickm}
            </>
            }
            {mapFxian.get('壁厚校核报告')?.do && <>
            </>
            }
            {mapFxian.get('射线检测报告')?.do && <>
                {renderRadioTs}
            </>}
            {mapFxian.get('超声波检测报告')?.do && <>
                {renderUtrSonic}
            </>}
            {mapFxian.get('磁粉检测报告')?.do && <>
                {magnetic}
            </>}

            {mapFxian.get('渗透检测报告')?.do && <>
                {permeation}
            </>}
            {mapFxian.get('光谱分析报告')?.do && <>
                {renderSpectrVs}
            </>}

            {mapFxian.get('硬度检测报告')?.do && <>
                {hardness}
            </>}
            {mapFxian.get('金相分析报告')?.do && <>
            </>
            }

            {mapFxian.get('安全附件检验报告')?.do &&
                安全附件检验({theme, orc, rep})
            }
            {/*安全阀校验  可能算单独的？ */}
            {mapFxian.get('安全阀校验报告')?.do && <>
            </>
            }
            {mapFxian.get('耐压试验报告')?.do && <>
            </>
            }

            {mapFxian.get('气密性试验报告')?.do && <>
                {gasproof}
            </>}
            {mapFxian.get('附加检验报告')?.do &&
                附加检验报告({theme, orc, rep})
            }
        </div>

        {末尾链接({template: rep?.modeltype, verId, repId: repId || ''})}
    </React.Fragment>
  );
}

